package com.fengkai.filepost.pdfoutstream.test.common.mq.producer;

import io.netty.channel.DefaultChannelId;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.util.concurrent.TimeUnit;

/**
 * @author Fengkai
 * @creat 2021/12/28
 */
public class OneProducer {

    public static void main (String[] args) throws Exception {
        DefaultMQProducer pg = new DefaultMQProducer("pg");

        pg.setNamesrvAddr("192.168.157.129:9876");
        //指定新创建的Topic的Queue数量为2 默认为4
        pg.setDefaultTopicQueueNums(2);
        DefaultChannelId.newInstance();
        pg.start();
        for (int i = 0; i < 100; i++) {
            byte[] body = ("HI," + i).getBytes();
            Message message = new Message("gulimail-product-msg", "singleTag", body);
            //为消息指定key
            message.setKeys("key-" + i);
            // 单向发送
            pg.sendOneway(message);
        }
        pg.shutdown();
    }
}